"""PropertyPhoto model for storing property images."""

from __future__ import annotations

from typing import TYPE_CHECKING

from sqlalchemy import ForeignKey, String
from sqlalchemy.orm import Mapped, mapped_column, relationship

from ..db.base_class import Base
from ..models.base import TimestampMixin

if TYPE_CHECKING:
    from ..models.property import Property


class PropertyPhoto(Base, TimestampMixin):
    """Property photo entity."""

    __tablename__ = "property_photos"

    id: Mapped[int] = mapped_column(primary_key=True, index=True)

    # Foreign Key
    property_id: Mapped[int] = mapped_column(
        ForeignKey("properties.id"), nullable=False, index=True, comment="关联房源ID"
    )

    # Photo Information
    photo_url: Mapped[str] = mapped_column(String(500), nullable=False, comment="照片URL/本地路径")
    photo_type: Mapped[str | None] = mapped_column(
        String(50), nullable=True, comment="照片类型(如: 客厅/卧室/厨房)"
    )
    display_order: Mapped[int | None] = mapped_column(nullable=True, default=0, comment="显示顺序")

    # Relationship
    property: Mapped[Property] = relationship("Property", back_populates="photos")
